package sketch.generator;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

import sketch.util.Randomness;

public class RandomValueGenerator<T> extends ValueGenerator<T> {
	
	private List<T> values = new ArrayList<T>();

	public RandomValueGenerator(T... values) {
		super();
		add(values);
	}
	
	public RandomValueGenerator(Collection<T> values) {
		super();
		for(T value : values) {
			add(value);
		}
	}
	
	public void add(T value) {
		values.add(value);
		//change the reset tag?
	}
	
	public void add(T...values) {
		for(T value : values) {
			add(value);
		}
	}

	@Override
	public T composeData() {
		throw new UnsupportedOperationException("composeData() is not supported in RandomValueGenerator yet!");
	}

	@Override
	protected T generateNext() {
		if(values.isEmpty()) {
			throw new IterationException("There is no stored values!");
		}
		int index = Randomness.nextRandomInt(values.size());
		return values.get(index);
	}

	@Override
	public boolean hasNext() {
		//return !values.isEmpty();
		return isReset();
	}

	@Override
	public List<T> nextWrappedValue() {
		T t = this.generateNext();
		return Collections.singletonList(t);
	}

}
